import { $http } from './index';

export function login(params = {}) {
    return $http.post('/pl/pack/login/usernameLogin', params);
}

export function loginWithEncrypt(params = {}) {
    return $http.post('/pl/pack/login/usernameLoginWithEncrypt', params);
}

export function loginBySms(params = {}) {
    return $http.post('/md/auth/phoneLogin', params);
}

// 三方系统跳转带 token 时，通过 token 重新获取登录信息
export function getUserSecureByToken(params = {}) {
    return $http.get(`pl/pack/login/getUserSecureByToken?token=${params.token}`);
}

export function secondAuth(params = {}) {
    return $http.post('/md/auth/secondAuth', params);
}

export function getUserInfo() {
    return $http.get('/md/user/getUserInfo');
}

export function getProductsCanAccess(params = {}) {
    return $http.get('/md/permission/product/accessible', params);
}

// TODO 这个好像对于每一个产品返回的值都是一样的 ...
export function getUserPermissionsByProduct(userId = '', productCode = '') {
    return $http.get('/md/permission/user/product', {
        params: {
            userId,
            productCode,
        },
    });
}

export function getSmsVerifyCode(params = {}) {
    return $http.post('/md/user/sendSmsCode', params);
}

// 这个 api 不需要传递 username，区别于上一个
export function sendSms(data = {}) {
    return $http.post('/md/user/sendSms', data);
}

export function changePassword(password = '', newPassword = '', repeatNewPassword = '') {
    return $http.post('/md/user/changePassword', {
        oldPwd: password,
        newPwd: newPassword,
        confirmNewPwd: repeatNewPassword,
    });
}
export function changePasswordWithOldPwd(data) {
    return $http.post('/md/user/changePassword', data);
}

export function ssoLogin(params = {}) {
    return $http.get('/md/sso/getTicket', {
        params,
    });
}

export function resetPassword(params = {}) {
    return $http.post('/md/user/resetPassword', params);
}

export function dingLogin(code = '', type = '') {
    return $http.get(`/pl/pack/login/dingLoginPuma?code=${code}&&loginType=${type}`);
}

export function wxLogin(code = '', agentId = '', productCode = '') {
    return $http.get(`/wl/wechat/login/receiveCode?code=${code}&agentId=${agentId}&productCode=${productCode}`);
}

export function wxSign(agentId = '', url = '') {
    return $http.get(`/wl/wechat/login/getTicket?agentId=${agentId}&&url=${url}`);
}

export function getProductInfoWithUrl(url = '') {
    return $http.get(`/md/product/getProductInfoWithUrl?url=${url}`);
}

export function countListMsg(params = {}) {
    return $http.post('/mcs/messageQuery/countListMsg', params);
}

// export function logOff(params = {}) {
//   return $http.post('/pl/pack/login/logout', params);
// }

export function logOff() {
    return $http.get('/pl/pack/login/logout');
}

export function getSfUrl(params = {}) {
    return $http.get('/md/url/getSfUrl', {
        params,
    });
}
